from twisted.internet.protocol import Protocol, Factory
from twisted.application import service, internet

from zope.interface import Interface, implements

class IManagedResource(Interface):
    pass

class IManagedEchoServer(IManagedResource):
    def shutdown():
        ""
    def start():
        ""
    def getConnections():
        ""
    def getUptime():
        ""
class EchoServerProbe(ManagedResource):
    pass

class ResourcesAgent(class):
    """
    MBeanServer
    """
    pass
 
class NotificationListener(object):
    def handleNotification(self, event):
        pass

agentListener = NotificationListener()

ra = ResourcesAgent()

class Echo(Protocol):

    # XXX this stuff probably needs to go in the factory
    pymxAgent = ra
    pymxAgent.createProbe(EchoServerProbe)
    pymxAgent.addEventListener(agentListener)

    def dataReceived(self, data):
        """
        As soon as any data is received, write it back.
        """
        self.transport.write('response: ' + data)
 

class EchoFactory(Factory):

    protocol = Echo
 
application = service.Application('myapp')
server = internet.TCPServer(7080, EchoFactory())
server.setServiceParent(application)
